package com.lg.cms.controller.error;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
//import org.springframework.boot.web.servlet.error.ErrorController;

/**
 * @Description: 错误页面视图控制器, 基本spring boot error
 * @Author: wuyuhang
 * @create: 2020-09-29 09:43
 */
@Controller
@Slf4j
public class MyErrorController implements ErrorController{

    @RequestMapping("/error")
    public String handleError(HttpServletRequest request){
        //获取statusCode:401,404,500
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
//        if(statusCode == 401){
//            return "/error/401";
//        }else if(statusCode == 403){
//            return "/error/403";
//        }else if(statusCode == 404) {
//            return "error/404";
//        }else if(String.valueOf(statusCode).startsWith("4")){
//
//        }
        switch (statusCode){
            case 400:
                return "error/400";
            case 401:
                return "error/401";
            case 403:
                return "error/403";
            case 404:
                return "error/404";
            case 500:
                return "error/500";
            case 503:
                return "error/503";
        }
        return null;
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}